package com.lifeservice.console.controller;

import com.lifeservice.common.annotation.Log;
import com.lifeservice.common.core.controller.BaseController;
import com.lifeservice.common.core.domain.AjaxResult;
import com.lifeservice.common.core.page.TableDataInfo;
import com.lifeservice.common.enums.BusinessType;
import com.lifeservice.common.utils.poi.ExcelUtil;
import com.lifeservice.console.domain.LifeBanner;
import com.lifeservice.console.service.ILifeBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 广告配置Controller
 *
 * @author lifeservice
 * @date 2023-03-03
 */
@RestController
@RequestMapping("/console/banner")
public class LifeBannerController extends BaseController {
    @Autowired
    private ILifeBannerService lifeBannerService;

    /**
     * 查询广告配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LifeBanner lifeBanner) {
        startPage();
        List<LifeBanner> list = lifeBannerService.selectLifeBannerList(lifeBanner);
        return getDataTable(list);
    }

    /**
     * 导出广告配置列表
     */
    @Log(title = "广告配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LifeBanner lifeBanner) {
        List<LifeBanner> list = lifeBannerService.selectLifeBannerList(lifeBanner);
        ExcelUtil<LifeBanner> util = new ExcelUtil<LifeBanner>(LifeBanner.class);
        util.exportExcel(response, list, "广告配置数据");
    }

    /**
     * 获取广告配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(lifeBannerService.selectLifeBannerById(id));
    }

    /**
     * 新增广告配置
     */
    @Log(title = "广告配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LifeBanner lifeBanner) {
        return toAjax(lifeBannerService.insertLifeBanner(lifeBanner));
    }

    /**
     * 修改广告配置
     */
    @Log(title = "广告配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LifeBanner lifeBanner) {
        return toAjax(lifeBannerService.updateLifeBanner(lifeBanner));
    }

    /**
     * 删除广告配置
     */
    @Log(title = "广告配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(lifeBannerService.deleteLifeBannerByIds(ids));
    }
}
